using System;
using System.Collections.Generic;
using Castle.ActiveRecord;

namespace demoapp.Models
{
	[ActiveRecord]
	public class Post	: ActiveRecordBase<Post>
	{
		private string m_title;
		private string m_content;
		private int id;
		IList<Comment> m_comments = new List<Comment>();

		public Post() {}

		public Post(string title)
		{
			m_title = title;
		}

		public Post(string title, string content)
		{
			m_title = title;
			m_content = content;
		}

		[PrimaryKey(PrimaryKeyType.HiLo)]
		public int Id
		{
			get { return id; }
			protected set { id = value; }
		}

		[Property]
		public string Title
		{
			get { return m_title; }
			set { m_title = value; }
		}

		[Property]
		public string Content
		{
			get { return m_content; }
			set { m_content = value; }
		}

		[HasMany(/*Fetch = FetchEnum.Join,*/ Inverse = true, Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)]
		public IList<Comment> Comments
		{
			get { return m_comments; }
			set { m_comments = value; }
		}

		public void AddComment(string author, string content)
		{
			Comment comment = new Comment(DateTime.Now, author, content);
			Comments.Add(comment);
			comment.Post = this;
		}
	}
}